<template>
	<view>
		
	<u-navbar :is-back="false" title="商品入库填写"
	  title-size="30"
	  :background="{background:'#2B88FE' }"
	  title-color="#fff">
	  <div class="head_icon">
	    <u-icon @click="$api.handleBackTo"
	      name="arrow-left" color="#fff"
	      size="36">
	    </u-icon>
	    <u-icon @click="$api.handleHomeTo"
	      name="home" color="#fff" size="36">
	    </u-icon>
	  </div>
	</u-navbar>	
		

  <div class="app-draw-add">

    <navigator url="/pages/sale/draw/drawSelect" class="draw-add">
      <u-icon name="plus" color="#2979ff" size="28"></u-icon> 添加入库商品
    </navigator>
    <appProduct v-for="(v,i) in formdata" :key="i" :li="v">

      <view slot="cell" style="display:flex">
        <span> 入库数量（{{v.fUnit}}）：</span>
        <u-input border type="text" v-model="v.fCount"></u-input>
      </view>
	  <view slot="cell" style="display:flex">
	    <span>入库数量（{{v.fPackUnit}}）：</span>
	    <u-input border type="text" v-model="v.fPackCount"></u-input>
	  </view>
      <view slot="cell" style="display:flex">
        <span> 生产日期：</span>
       <span class="scDate"
             @click="handleCell(v)">{{v.fExTime}}
       <u-icon name="arrow-right"></u-icon>
   </span>
      </view>
    </appProduct>
    <div class="draw-mark">
      <span>备注（非必填）</span>
      <u-input type="textarea" v-model="info.Info" border></u-input>
    </div>
	<u-picker v-model="show" mode="time"
	  :default-time="orderItem.fExTime"
	  :params="params"
	  @confirm="handleSelectDate">
	</u-picker>
	
    <div class="app-footer">
      <u-button>取消</u-button>
      <u-button type="primary" @click="handleSave">提交</u-button>
    </div>
  </div>
	</view></template>

<script>
import appProduct from '@/components/app-product'
export default {
  components: {
    appProduct
  },
  data() {
    return {
		params: {
		  year: true,
		  month: true,
		  day: true
		},
	  show: false,
      info: {
        InOut: 2,
        iType: 1,
        CarId: 0,
        CarNo: '',
        Info: ''
      },
	    clineOnce:true,
      formdata: [],
	   orderItem: {},
      list: []
    }
  },
  methods: {
    handleCell(item) {
      console.log('🚀 ~ file: my_customer_stock_add.vue ~ line 113 ~ handleCell ~ item', item)
      this.orderItem = item
      this.show = true
    },
    handleSelectDate(e) {
      this.orderItem.fExTime = `${e.year}-${e.month}-${e.day} `
    },
	  
    handleSave() {
		if (!this.clineOnce) return false
		this.clineOnce = false
      this.$axios('api/ProInAndOut/ManageAddProIn', 'post', { value: this.info }).then(ret => {
        this.list.forEach(x => (x.InAndOutId = ret.Value))
        let list = this.formdata.map(x => ({
          Count: x.fCount,
          InAndOutId: ret.Value,
          ProId: x.fId,
          ProName: x.gname,
          ExTime: x.fExTime,
		   Unit: x.fUnit,
		   PackCount: x.fPackCount,
		   PackUnit: x.fPackUnit,
          Info: x.Info
        }))
        this.list = [].concat.apply(this.list, list)
        this.$axios('api/ProInAndOutList/ManageAddList', 'post', { value: this.list }).then(res => {
          	this.clineOnce = true
		  this.$api.handleBack('添加成功')
          getApp().globalData.addCusGoodLi = null
        })
      })
    }
  },
  onShow() {
    if (getApp().globalData.addCusGoodLi) {
      let orders = getApp().globalData.addCusGoodLi
   
	  orders.forEach(x => ((x.details = [{ label: '现有散装', value: x.fCount },{ label: '现有整装', value: x.fPackCount }]), (x.fCount = 0), (x.fPackCount = 0)))
      this.formdata = orders
    }
  },
  created() {}
}
</script>

<style lang="scss" scoped>
.app-draw-add {
  padding-bottom: 70rpx;
  .draw-item {
    .title {
      font-size: 30rpx;
      color: #7f7f7f;
      margin-top: 30rpx;
      margin-left: 30rpx;
    }
  }
  .draw-add {
    color: #007aff;
    font-size: 30rpx;
    padding: 32rpx;
    text-align: center;
  }
  .draw-mark {
    display: flex;
    padding: 0 32rpx;
    u-input {
      flex: 1;
    }
  }
}
</style>